﻿// -----------------------------------------------------------------------
// <copyright file="IMG_GreyLevelSlicing.cs" company="Hewlett-Packard">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace ImageProcessing.ImageProcessor
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// IMG_GreyLevelSlicing class
    /// </summary>
    public static class IMG_GreyLevelSlicing
    {
        /// <summary>
        /// grey slicing with diminsh other levels.
        /// </summary>
        /// <param name="imgOrgininalGrey">The img orgininal grey.</param>
        /// <param name="minVal">The min val.</param>
        /// <param name="maxVal">The max val.</param>
        /// <param name="a">A value</param>
        /// <param name="b">The b.</param>
        /// <returns>sliced image</returns>
        public static Entities.IMG_Image IMG_GreySlicingWithDiminshOtherLevels(Entities.IMG_Image imgOrgininalGrey, int minVal, int maxVal, int a, int b)
        {
            try
            {
                int width = imgOrgininalGrey.Width;
                int height = imgOrgininalGrey.Height;
                int index = width * height;
                Entities.IMG_Image imgRetured = new Entities.IMG_Image(width, height);
                for (int i = 0; i < index; i++)
                {
                    int value = (int)imgOrgininalGrey.ImagePixels[i].Red;
                    if (value >= a && value <= b)
                    {
                        imgRetured.ImagePixels[i] = new Entities.Pixel(maxVal, maxVal, maxVal);
                    }
                    else
                    {
                        imgRetured.ImagePixels[i] = new Entities.Pixel(minVal, minVal, minVal);
                    }
                }

                return imgRetured;
            }
            catch (Exception img_Ex)
            {
                Logger.LogException(img_Ex);
                throw;
            }
        }

        /// <summary>
        /// IMs the g_ grey slicing keep data.
        /// </summary>
        /// <param name="imgOrgininalGrey">The img orgininal grey.</param>
        /// <param name="maxVal">The max val.</param>
        /// <param name="a">A value </param>
        /// <param name="b">The b.</param>
        /// <returns>the sliced image</returns>
        public static Entities.IMG_Image IMG_GreySlicingKeepData(Entities.IMG_Image imgOrgininalGrey, int maxVal, int a, int b)
        {
            try
            {
                int width = imgOrgininalGrey.Width;
                int height = imgOrgininalGrey.Height;
                int index = width * height;
                Entities.IMG_Image imgRetured = new Entities.IMG_Image(width, height);
                for (int i = 0; i < index; i++)
                {
                    int value = (int)imgOrgininalGrey.ImagePixels[i].Red;
                    if (value >= a && value <= b)
                    {
                        imgRetured.ImagePixels[i] = new Entities.Pixel(maxVal, maxVal, maxVal);
                    }
                    else
                    {
                        imgRetured.ImagePixels[i] = imgOrgininalGrey.ImagePixels[i];
                    }
                }

                return imgRetured;
            }
            catch (Exception img_Ex)
            {
                Logger.LogException(img_Ex);
                throw;
            }
        }
    }
}
